﻿package com.cilico.single.components;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;

import com.cilico.single.utils.Utils;
import com.cilico.single.view.BaseView;
import com.cilico.single.view.FormLayout;

/**
 * 控件接口
 * @author lv.xiangan
 *
 */
public interface Component {

	static final int MAX_SPACE_AFTER_LABEL = 60;
	static final int INTERNAL_AFTER_LABEL = 4;
	static final int INTERNAL_BELOW_LABEL = 4;
	static final int MAX_WIDTH = Utils.screenWidth_ - BaseView.SCROLL_BAR_AREA_WIDTH
			- BaseView.SCROLL_BAR_RIGHT_MARGIN - BaseView.ITEM_LEFT_MARGIN - BaseView.X_MARGIN * 2;

	static final char LABEL_CHAR = ':';
	static final int MAX_ROW_WIDTH = Utils.screenWidth_ - Utils.getSystemScaledValue(20);
	public static class SelfLayout extends LinearLayout implements Component {

		public SelfLayout(Context context) {
			super(context);
		}

		public int getRealWidth() {
			int w = 0;
			int size = getChildCount();
			for (int i = 0; i < size; i++) {
				View v = getChildAt(i);
				if (v instanceof SelfLayout) {
					w += ((SelfLayout) v).getRealWidth();
				} else {
					try {
						w += ((Component) v).getCmpWidth();
						LayoutParams lp = (LinearLayout.LayoutParams) v.getLayoutParams();
						w += lp.leftMargin + lp.rightMargin;
					} catch (Exception e) {
						Utils.printException(e);
					}
				}
			}
			return w;
		}

		public int getRealHeight() {
			int h = 0;
			int size = getChildCount();
			for (int i = 0; i < size; i++) {
				View v = getChildAt(i);
				if (v instanceof SelfLayout) {
					h += ((SelfLayout) v).getRealHeight();
				} else {
					try {
						LayoutParams lp = (LinearLayout.LayoutParams) v.getLayoutParams();
						h += ((Component) v).getCmpHeight() + lp.topMargin + lp.bottomMargin;
					} catch (Exception e) {
						// TODO Auto-generated catch block
						Utils.printException(e);
					}
				}
			}
			return h;
		}

		public void cleanText() {
			// TODO Auto-generated method stub

		}

		public String getContentText() {
			// TODO Auto-generated method stub
			return null;
		}

		public CssStyle getCssStyle() {
			// TODO Auto-generated method stub
			return null;
		}

		public int getCmpHeight() {
			// TODO Auto-generated method stub
			return 0;
		}

		public View getCmpView() {
			// TODO Auto-generated method stub
			return null;
		}

		public int getCmpWidth() {
			// TODO Auto-generated method stub
			return 0;
		}

		public boolean isInTable() {
			// TODO Auto-generated method stub
			return false;
		}

		public void mould() {
			// TODO Auto-generated method stub

		}

		public void releaseResource(View view) {
			// TODO Auto-generated method stub
			Utils.releaseResource(view);
		}

		public void setContentText(String text) {
			// TODO Auto-generated method stub

		}

		public void setCssStyle(CssStyle style) {
			// TODO Auto-generated method stub

		}

		public void setInTable(boolean inTable) {
			// TODO Auto-generated method stub

		}

		public void setCmpHeidht(int height) {
			// TODO Auto-generated method stub

		}

		public void setCmpWidth(int width) {
			// TODO Auto-generated method stub

		}

		public void shrinkWidth() {
			// TODO Auto-generated method stub

		}

		public void setForm(FormLayout formLayout) {
			// TODO Auto-generated method stub

		}

		public FormLayout getForm() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public void setEncrypt(String encrypt) {
			// TODO Auto-generated method stub

		}
	}

	String getContentText();

	void setContentText(String text);

	void shrinkWidth();

	void cleanText();

	/**
	 * Mould this component with its shape, color, size and so on.
	 */
	public void mould();

	void setCmpWidth(int width);

	int getCmpWidth();

	void setCmpHeidht(int height);

	int getCmpHeight();

	void setCssStyle(CssStyle style);

	View getCmpView();

	void setInTable(boolean inTable);

	boolean isInTable();

	CssStyle getCssStyle();

	void releaseResource(View view);

	/**
	 *  添加该方法主要是由于联动还需要检测对应的父级form控件
	 * @param formLayout
	 */
	void setForm(FormLayout formLayout);

	FormLayout getForm();

	void setEncrypt(String encrypt);
}
